package com.carter.springframework.core.annotation;

import com.sun.istack.internal.Nullable;

import java.lang.annotation.Annotation;

interface AnnotationsProcessor<C,R> {
    @Nullable
    default R doWithAggregate(C context, int aggregateIndex) {
        return null;
    }

    /**
     * 扫描后的回调，返回的对象用于下一次扫描，当返回为空的时中断扫描
     * @param context
     * @param aggregateIndex
     * @param source
     * @param annotations
     * @return
     */
    @Nullable
    R doWithAnnotations(C context, int aggregateIndex, @Nullable Object source, Annotation[] annotations);

    /**
     * Get the final result to be returned. By default this method returns
     * the last process result.
     * @param result the last early exit result, or {@code null} if none
     * @return the final result to be returned to the caller
     */
    @Nullable
    default R finish(@Nullable R result) {
        return result;
    }
}
